<?php

class SliderObject {

	private $_id;
	private $_title;
	private $_img;
	
	public function __construct($data) {
		$this->hydrate($data);
		$this->constructImg();
	}
	
	public function hydrate(array $data) {
		foreach ($data as $key => $value) {
			$method = 'set'.ucfirst($key);
			if (method_exists($this, $method)) {
				$this->$method($value);
			}
		}
	}
	
	public function constructImg() {
		$extensions = Array(".jpg",".png");
		foreach ($extensions as $extension) {
			$img = PATH_DATAS.'slider/'.$this->_id.'/thumb'.$extension;
			if (file_exists($img)) {
				$img = URL_DATAS.'slider/'.$this->_id.'/thumb'.$extension;
				$this->setImg($img);
			}
		}
	}
	
	public function id() {
		return $this->_id;
	}
	
	public function title() {
		return $this->_title;
	}
	
	public function img() {
		return $this->_img;
	}
	
	public function setId($id) {
		$this->_id = intval($id);
	}
	
	public function setTitle($title) {
		if (is_string($title)) {
			$this->_title = $title;
		}
	}
	
	public function setImg($img) {
		if (is_string($img)) {
			$this->_img = $img;
		}
	}
	
}

?>